package com.byit.controller;
/**
 * Created by marker on 2018/3/6.
 */

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.byit.builder.MapBuilder;
import com.byit.constant.DefaultValue;
import com.byit.domain.AppApplication;
import com.byit.domain.vo.ApplicationFigure;
import com.byit.domain.vo.ContactUsVo;
import com.byit.domain.vo.IntroduceVo;
import com.byit.enums.PromptInfo;
import com.byit.msg.MessageResult;
import com.byit.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 配置接口
 **/
@Slf4j
@RestController
@RequestMapping("/app/config")
public class AppConfigController {

    /**
     * ConfigService
     */
    @Autowired
    private ConfigService configService;

    /**
     * 联系我们
     * @return
     * @author wumin
     */
    @GetMapping("/getContactUs")
    public Object getContactUs(String configKey) {


        ContactUsVo contactUsVo = configService.getContactUs(ContactUsVo.CONFIG_KEY);
        return MessageResult.success(contactUsVo);
    }

    /**
     * 获取app形象广告列表
     * @return
     * @author wumin
     */
    @GetMapping("/applicationFigure/list")
    public Object applicationFigureList(
            @RequestParam(value = "page", defaultValue = DefaultValue.PAGE_FIRST) int page,
            @RequestParam(value = "limit", defaultValue = DefaultValue.PAGE_SIZE) int limit) {
        Page<AppApplication> pageInfo = new Page<>(page, limit);

        Page<JSONObject> pageData = configService.getApplicationFigureList(pageInfo, MapBuilder.newMap(1)
                .setParam("key",  ApplicationFigure.CONFIG_KEY + '%')
                .ok());

        return MessageResult.warpper(PromptInfo.SYS_SECCUSS, pageData);
    }

    /**
     * 获取app形象广告
     * @return
     * @author wumin
     */
    @GetMapping("/getApplicationFigure")
    public Object getApplicationFigure(
            HttpSession session, String appId) {


        ApplicationFigure applicationFigure = configService.getApplicationFigure(ApplicationFigure.CONFIG_KEY+appId);
        return MessageResult.success(applicationFigure);
    }

    /**
     * 获取app图文和视频介绍
     * @return
     * @author wumin
     */
    @GetMapping("/getIntroduce")
    public Object getIntroduce(
            HttpSession session, String configKey) {


        IntroduceVo introduce = configService.getIntroduce(IntroduceVo.CONFIG_KEY);
        return MessageResult.success(introduce);
    }


}
